//
//  YFRetweetView.swift
//  微博
//
//  Created by 余仿 on 16/4/13.
//  Copyright © 2016年 YF. All rights reserved.
//

import UIKit

import SnapKit

class YFRetweetView: UIView {

        var bottomCons:Constraint?

 /// 微博正文
    private var contentLabel:UILabel = UILabel(title: "内容", fontSize: 14, fontColor: UIColor.darkTextColor(),margin: screenWidth - 2 * statusCellMargin)

    //图片
    private lazy var pictureView:YFPictureView = YFPictureView()

    var statusViewModel:YFStatusViewModel?{

        didSet{

            contentLabel.text = "\(statusViewModel?.statusList?.retweeted_status?.user?.name ?? ""):\(statusViewModel?.statusList?.retweeted_status?.text ?? "")"

            //get图片赋值
            pictureView.picUrls = statusViewModel?.statusList?.retweeted_status?.pic_urls

            updateBottomCons()

        }
    }

    func updateBottomCons(){

        self.bottomCons?.uninstall()

        if statusViewModel?.statusList?.pic_urls != nil{
            //说明有图片
            self.snp_makeConstraints(closure: { (make) -> Void in
                self.bottomCons = make.bottom.equalTo(pictureView.snp_bottom).offset(statusCellMargin).constraint
            })

            pictureView.hidden = false


        }else{
            //说明没图片
            self.snp_makeConstraints(closure: { (make) -> Void in
                self.bottomCons = make.bottom.equalTo(contentLabel.snp_bottom).offset(statusCellMargin).constraint
            })
            pictureView.hidden = true
        }
        
    }




    override init(frame: CGRect) {

        super.init(frame: frame)

        contentLabel.backgroundColor = UIColor(white: 0.9, alpha: 1)
        //添加子控件
        addSubview(contentLabel)
        addSubview(pictureView)
        //布局
        setupUI()
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

   private func setupUI(){

        contentLabel.snp_makeConstraints { (make) -> Void in
            make.left.top.equalTo(self).offset(statusCellMargin)
        }

    pictureView.snp_makeConstraints { (make) -> Void in
        make.top.equalTo(contentLabel.snp_bottom).offset(statusCellMargin)
        make.left.equalTo(contentLabel.snp_left)
        make.size.equalTo(CGSize(width: 80, height: 80))
    }



        self.snp_makeConstraints { (make) -> Void in
           self.bottomCons = make.bottom.equalTo(pictureView.snp_bottom).offset(statusCellMargin).constraint
    }

    }


}
